#include<stdio.h>

//顺序查找
int seq_search(int array[] ,int n,int k, int seek_seq[] )
{

    for (int i = 0;i<n;i++)
    {
        if (array[i] == k) {
            seek_seq[i] = i;
            return 0;
        }else
            seek_seq[i] = i;
    }
    return -1;
}

//二分查找
int bin_search(int array[] ,int n,int k, int seek_seq[] )
{
    int low = 0, mid, high = n - 1,i=0;
    if (low>high){
        return -1;
    }
    do {
        mid = (low + high)/2 ;
        if (k < array[mid])
        {
            high = mid - 1;
            seek_seq[i] = mid;
        }else if (k > array[mid])
        {
            low = mid + 1;
            seek_seq[i] = mid;
        }
        else{
            seek_seq[i] = mid;
            return 0;
        }
        i++;
    } while (low<=high);
}
int main() {
    int n = 5;
    int array[] = {26, 34, 35, 56, 89};
    int seek_seq[5];

    for (int j = 0; j < n; j++) {
        seek_seq[j] = -1;
    }
    seq_search(array, 5, 89, seek_seq);
    for (int i = 0; i < n; i++) {
        if (seek_seq[i] < 0) {
            break;
        }
        printf("当前位置%d  ", seek_seq[i]);
    }

    printf("\n");

    for(int j = 0;j<n;j++){
        seek_seq[j] = -1;
    }
    bin_search(array,5,89,seek_seq);
    for(int i = 0;i<n;i++){
        if(seek_seq[i] < 0){
            break;
        }
        printf("当前位置%d  ",seek_seq[i]);
    }
}
